package com.humngyang.com.hmy.study.concurrency.myannoations.aqs;

import com.humngyang.com.hmy.study.concurrency.myannoations.collection.CopyOnWriteArraySetExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CountDownLatchExample {
    private static Logger log = LoggerFactory.getLogger(CountDownLatchExample.class);
    private static  int  threadTotal = 5000;

    public static void main(String[] args) throws InterruptedException {
        final CountDownLatch countDownLatch = new CountDownLatch(threadTotal);
        ExecutorService exec = Executors.newCachedThreadPool();

        for (int i = 0; i <threadTotal ; i++) {
            final int threadNum = i;
            exec.execute(()->{
                try {
                    dealWith(threadNum);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    countDownLatch.countDown();
                }
            });
        }
        countDownLatch.await();
        log.info("finsh");
        exec.shutdown();

    }
    public static void dealWith(int index) throws InterruptedException {
        Thread.sleep(100);
        log.info("当前的数量为===》 {}",index);
        Thread.sleep(100);
    }
}
